<?php

/*
Plugin Name: Sandbox
Plugin Author: Maia Engeli
*/

function syn_findusers(){
	global $wpdb;

	echo "Members: <br />";
	$result = $wpdb->get_results("SELECT `ID` FROM `{$wpdb->prefix}users`"); 
	foreach ($result as $r) {
		echo ($r->ID . " ");
		$user_info = get_userdata($r->ID);
 		echo($user_info->first_name .  " " . $user_info->last_name . "<br />\n");
	}
}

function syn_formatting(){
?>
<h1>H1 Title</h1>
    <h2>H2 Title</h2>
    <h3>H3 Title    </h3>
    <h4>H4 Title</h4>
    <p>just some normal paragraph text</p>
    <p>unordered list of items</p>
    <ul>
      <li>item one</li>
      <li>item two</li>
      <li>item three</li>
    </ul>
    <p>ordered list of items</p>
    <ol>
      <li>item four</li>
      <li>item five</li>
      <li>item six</li>
    </ol>
<p>and a link:</p>
<p><a href="wordpress.org">www.wordpress.org</a></p>
    
<?php	
}

function widget_syn_sandbox($args) {
    extract($args);
	echo $before_widget; 
 	echo $before_title . 'Sandbox' . $after_title;
	$user = wp_get_current_user();
	echo "logged in as<b> $user->display_name </b><br />"; 
	syn_formatting();
	syn_findusers();
	echo $after_widget; 
}
register_sidebar_widget('Sandbox', 'widget_syn_sandbox');

function syn_sandbox_install() {
	global $wpdb;
	$table = $wpdb->prefix."sandbox";
	$schema = "CREATE TABLE $table (
        id INT(9) NOT NULL AUTO_INCREMENT,
        name VARCHAR(80),
        count INT(9) DEFAULT 0,
		UNIQUE KEY id (id)
    );";
	$wpdb->query($schema);
	$wpdb->query("INSERT INTO $table(name, count)
        VALUES('maiatest', '0')");
	$wpdb->query("INSERT INTO $table(name, count)
        VALUES('test2', '1')");
}
add_action('activate_syn_proj_mgmt/syn_proj_mgmt.php', 'project_install');

?> 